package com.example.controller;

import cn.hutool.core.util.StrUtil;
import com.example.enums.ErrorCode;
import com.example.exception.BusinessException;
import com.example.model.dto.DrawDto;
import com.example.model.dto.ImageStyleTransDto;
import com.example.service.AiService;
import com.example.utils.Result;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

/**
 * @author lzh
 */
@RestController
@RequestMapping("/ai")
public class AiController {

    @Resource
    private AiService aiService;

    @GetMapping("/detect")
    public Result<List<String>> detectFace(String path) throws IOException {
        if (StrUtil.isBlank(path)) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        List<String> result = aiService.detectFace(path);
        return Result.success(result);
    }

    @GetMapping("/toAnime")
    public Result<String> toAnime(String path) throws IOException {
        if (StrUtil.isBlank(path)) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        String result=aiService.toAnime(path);
        return Result.success(result);
    }

    @PostMapping("/AiDraw")
    public Result<String> AiDraw(@RequestBody DrawDto drawDto) throws IOException {
        String result=aiService.AiDraw(drawDto);
        return Result.success(result);
    }

    @PostMapping("/imageStyleTrans")
    public Result<String> imageStyleTrans(@RequestBody ImageStyleTransDto imageStyleTransDto) throws IOException {
        String result=aiService.imageStyleTrans(imageStyleTransDto);
        return Result.success(result);
    }

}
